package com.huawei.fastengine.fastview.startFastappEngine;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import com.huawei.fastengine.fastview.Config;
import com.huawei.fastengine.fastview.OpenFastAppEngine;
import com.huawei.fastengine.fastview.StartFastAPPEngine;
import com.huawei.fastengine.fastview.download.emui.widget.EMUISupportUtil;
import com.huawei.fastengine.fastview.download.utils.CommonUtils;
import com.huawei.fastengine.fastview.download.utils.log.FastViewLogUtils;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.lang.reflect.InvocationTargetException;

public class JumpActivity extends Activity {
    public static final String ACTIVITY_NAME = "com.huawei.fastapp.app.protocol.JumpActivity";
    private static final int MSG_TIMEOUT = 1000;
    private static final int REQUEST_CODE = 2001;
    private static final String TAG = "JumpActivity";
    private static final int TIME_OUT = 2000;
    private boolean isfromold = false;
    private Handler mHandler = new Handler() {
        public void handleMessage(Message message) {
            if (1000 == message.what) {
                JumpActivity.this.setStatus(false);
            }
        }
    };
    private OpenFastAppEngine mInstance;
    private StartFastAPPEngine mInstanceold;

    private static void requestActivityTransparent(Activity activity) {
        activity.requestWindowFeature(1);
        if (EMUISupportUtil.getInstance().isEMUI4Style()) {
            Window window = activity.getWindow();
            window.addFlags(HwAccountConstants.FLAG_TRANSLUCENT_STATUS);
            setHwFloating(window, true);
        }
    }

    private static void setHwFloating(Window window, boolean z) {
        try {
            window.getClass().getMethod("setHwFloating", new Class[]{Boolean.TYPE}).invoke(window, new Object[]{Boolean.valueOf(z)});
            return;
        } catch (NoSuchMethodException e) {
        } catch (IllegalAccessException e2) {
        } catch (IllegalArgumentException e3) {
        } catch (InvocationTargetException e4) {
        }
        FastViewLogUtils.e(TAG, "Failed to call Window.setHwFloating().");
    }

    private void setStatus(boolean z) {
        FastViewLogUtils.d(TAG, "setStatus: " + z);
        if (this.isfromold) {
            if (this.mInstanceold != null) {
                FastViewLogUtils.d(TAG, "isfromold setStatus: mInstance is not null");
                this.mInstanceold.setJumpActivityStatus(z);
            }
        } else if (this.mInstance != null) {
            FastViewLogUtils.d(TAG, "setStatus: mInstance is not null");
            this.mInstance.setJumpActivityStatus(z);
        }
        finish();
    }

    private void startActivityForResult() {
        FastViewLogUtils.d(TAG, " startActivityForResult：");
        Intent intent = new Intent();
        intent.setClassName(Config.FASTAPP_PACKAGE_NAME, ACTIVITY_NAME);
        try {
            startActivityForResult(intent, 2001);
            overridePendingTransition(0, 0);
            Message obtain = Message.obtain(this.mHandler);
            obtain.what = 1000;
            this.mHandler.sendMessageDelayed(obtain, 2000);
        } catch (ActivityNotFoundException e) {
            FastViewLogUtils.e(TAG, "ActivityNotFoundException");
            this.mHandler.removeMessages(1000);
            setStatus(false);
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        FastViewLogUtils.d(TAG, " onActivityResult: " + i2);
        if (this.mHandler != null) {
            this.mHandler.removeMessages(1000);
        }
        boolean z = false;
        if (i == 2001 && i2 == -1) {
            z = true;
        }
        setStatus(z);
        finish();
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestActivityTransparent(this);
        Intent intent = getIntent();
        if (!(intent == null || CommonUtils.hasParseException(intent))) {
            this.isfromold = intent.getBooleanExtra("isfromold", false);
        }
        if (this.isfromold) {
            this.mInstanceold = StartFastAPPEngine.getInstance();
        } else {
            this.mInstance = OpenFastAppEngine.getInstance();
        }
        startActivityForResult();
    }

    protected void onPause() {
        overridePendingTransition(0, 0);
        super.onPause();
    }
}
